package com.mes.inventory.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Dept;
import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;

/**
 * <p>
 * InvWarehouse实体，代表库房。
 * </p>
 * author lcs
 * data 2017-03-19
 */
@Entity()
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "I_WAREHOUSE")
@BatchSize(size=10)
@Lazy(value=true)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Warehouse extends BasicModel implements Serializable {

	// Fields
	public final static String  DEFAULT_BIN_ID_NAME = "NA"; 

	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name="UNIQUEID",length=50)
	protected String uniqueId;
	
	@Column(name="WAREHOUSEID",length=50)
	protected String warehouseId;
	
	@Column(name="WAREHOUSENAME",length=50)
	protected String warehouseName;
	
	@Column(name="PARENTWAREHOUSEID",length=50)
	protected String parentWarehouseUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="PARENTWAREHOUSEID",insertable=false,updatable=false)
	protected Warehouse parentWarehouse;
	
    @Column(name="WAREHOUSETYPE",length=50)
	protected String warehouseType;
    
//    //many-to-one
//	@ForeignKey(name="null")
//	@ManyToOne(fetch=FetchType.LAZY)
//	@JoinColumnsOrFormulas(value={
//			@JoinColumnOrFormula(column=@JoinColumn(name="WAREHOUSETYPE",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
//			@JoinColumnOrFormula(formula=@JoinFormula(value="'warehousetype'", referencedColumnName="TYPESNAME"))
//	})
//	protected TypesData warehouseTypeDesc;
	
	/**
	 * 复杂对象映射--warehouseManager
	 */
	@Column(name="MANAGER",length=50)
	protected String warehouseManagerUid;	
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="MANAGER",insertable=false,updatable=false)
	protected Employee warehouseManager;
	
	@Column(name="ADDRESS",length=50)
	protected String address;
	
	@Column(name="DEPTID")
	protected String deptUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="DEPTID",insertable=false,updatable=false)
	protected Dept dept;
	
	
	/** default constructor */
	public Warehouse() {
	}

	/**
	 * 获取库房名称
	 * @return
	 */
	public String getWarehouseName() {
		return warehouseName;
	}

	/**
	 * 设置库房名称
	 * @param warehousename
	 */
	public void setWarehouseName(String warehouseName) {
		this.warehouseName = warehouseName;
	}

	/**
	 * 获取父库房编号
	 * @return
	 */
	public String getParentWarehouseUid() {
		return parentWarehouseUid;
	}

	/**
	 * 设置父库房编号
	 * @param parentWarehouseUid
	 */
	public void setParentWarehouseUid(String parentWarehouseUid) {
		this.parentWarehouseUid = parentWarehouseUid;
	}

	/**
	 * 获取父库房对象
	 * @return
	 */
	public Warehouse getParentWarehouse() {
		return parentWarehouse;
	}

	/**
	 * 设置父库房对象
	 * @param parentWarehouse
	 */
	public void setParentWarehouse(Warehouse parentWarehouse) {
		this.parentWarehouse = parentWarehouse;
	}

	/**
	 * 获取库房类型
	 * @return
	 */
	public String getWarehouseType() {
		return warehouseType;
	}

	 // 设置库房类型
	 // @param warehousetype
	 
	public void setWarehouseType(String warehouseType) {
		this.warehouseType = warehouseType;
	}

	/**
	 * 获取库房管理员编号
	 * @return
	 */
	public String getWarehouseManagerUid() {
		return warehouseManagerUid;
	}

	/**
	 * 设置库房管理员编号
	 * @param warehouseManagerUid
	 */
	public void setWarehouseManagerUid(String warehouseManagerUid) {
		this.warehouseManagerUid = warehouseManagerUid;
	}

	/**
	 * 获取库房管理员对象
	 * @return
	 */
	public Employee getWarehouseKeeper() {
		return warehouseManager;
	}

	/**
	 * 设置库房管理员对象
	 * @param warehouseManager
	 */
	public void setWarehouseKeeper(Employee warehouseManager) {
		this.warehouseManager = warehouseManager;
	}

	/**
	 * 获取地址
	 * @return
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * 设置地址
	 * @param address
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * 获取部门编号
	 * @return
	 */
	public String getDeptUid() {
		return deptUid;
	}

	/**
	 * 设置部门编号
	 * @param deptUid
	 */
	public void setDeptUid(String deptUid) {
		this.deptUid = deptUid;
	}

	/**
	 * 获取部门对象
	 * @return
	 */
	public Dept getDept() {
		return dept;
	}

	/**
	 * 设置部门对象
	 * @param dept
	 */
	public void setDept(Dept dept) {
		this.dept = dept;
	}


	/**
	 * 库房缺省柜位为库房编号 加上 缺省柜位名称
	 * @return库房缺省的柜位
	 */
	public String getDefaultWarebinUid() {
		return this.uuid + "-" + DEFAULT_BIN_ID_NAME;
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getUniqueId();
	}
	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setUniqueId(uuid);
	}
	
	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public String getWarehouseId() {
		return warehouseId;
	}

	public void setWarehouseId(String warehouseId) {
		this.warehouseId = warehouseId;
	}

	public Employee getWarehouseManager() {
		return warehouseManager;
	}

	public void setWarehouseManager(Employee warehouseManager) {
		this.warehouseManager = warehouseManager;
	}




}